<?php
/**
 * Formulaire modification du profile
 *
 * @author Samir
 */
class Form_UpdateProfil extends ZendX_JQuery_Form {
	private $table_Persons;
	public $userId = 1;
	public function __construct($options = null){
		parent::__construct($options);
		$this->table_Persons = new Model_Database_PersonDb();
	}
	
	public function init(){

		require_once APPLICATION_PATH . '../decorators/formElementDecorator.php';
		
		$decorators = new Decorator_FormElement();
		
		$this->setName('form_update');
		
        $firstname = new Zend_Form_Element_Text('firstname');
		$firstname->setAutoInsertNotEmptyValidator(true);
		$firstname->setRequired(true)
	         //->setValue('samir')
	         ->addFilter('StripTags')
	         ->addFilter('StringTrim')
	         ->setAttrib('class', 'textfield')
	         ->addValidator('NotEmpty')
	         ->setLabel(('PERSON FIRSTNAME'))
			 ->addDecorator($decorators);	
		$this->addElement($firstname);	
		
		// add person lastname
		$lastname = new Zend_Form_Element_Text('lastname');
		//$lastname->setAutoInsertNotEmptyValidator(true)
		$lastname->setRequired(true)
	         //->setValue($data['lastname'])
	         ->addFilter('StripTags')
	         ->addFilter('StringTrim')
	         ->setAttrib('class', 'textfield')
	         
	         ->setLabel(('PERSON LASTNAME'))
	          
			 ->addDecorator($decorators);
		$this->addElement($lastname);	

		// add person lastname	 
        //$this->addElement('Select', 'civilite', array('MultiOptions' => array("" => "Choisir...", "monsieur" => "Monsieur", "mademoiselle" => "Mademoiselle", "madame" => "Madame", "pere" => "Père", "frere" => "Frère", "Soeur" => "Soeur" ), 'decorator' => $decorators, "label" => ("CIVILITE")));
        $civilite = new Zend_Form_Element_Select('civility');
		$civilite->setLabel('CIVILITE')
           		 ->addMultiOptions(array("" => "Choisir...", "monsieur" => "Monsieur", "mademoiselle" => "Mademoiselle", "madame" => "Madame", "pere" => "Père", "frere" => "Frère", "Soeur" => "Soeur" ))
            	->setRequired(true)
            	->addDecorator($decorators);
        $this->addElement($civilite);
           
        // add person email
		$email1 = new Zend_Form_Element_Text('email');
		$email1->setAutoInsertNotEmptyValidator(true)
			 //->setValue($data['email'])
	         ->setRequired(true)
	         ->addFilter('StripTags')
	         ->addFilter('StringTrim')
	         ->setAttrib('class', 'textfield')
	         ->addValidator('NotEmpty')
	         ->setLabel(('PERSON EMAIL'))
			 ->addDecorator($decorators);;	
		 $this->addElement($email1);	

		 $mailCheck1 = new Zend_Form_Element_Checkbox('email_show');
		 $mailCheck1->addFilter('StripTags')
	        	 	 ->addFilter('StringTrim')
	        	 	 ->setLabel(("J'accepte que ces informations figurent dans l'annuaire de l'intranet "));
	     $this->addElement($mailCheck1);			 
		 
		$email2 = new Zend_Form_Element_Text('email2');
		$email2->setAutoInsertNotEmptyValidator(true)
			 //->setValue($data['email'])
	         ->setRequired(true)
	         ->addFilter('StripTags')
	         ->addFilter('StringTrim')
	         ->setAttrib('class', 'textfield')
	         ->addValidator('NotEmpty')
	         ->setLabel(('PERSON EMAIL 2'))
			 ->addDecorator($decorators);
		 $this->addElement($email2);	

		 $mailCheck2 = new Zend_Form_Element_Checkbox('email_show2');
		 $mailCheck2->addFilter('StripTags')
	        	 	 ->addFilter('StringTrim')
	        		 ->setLabel(("J'accepte que ces informations figurent dans l'annuaire de l'intranet"))
	        		 ->addDecorator($decorators);
	     $this->addElement($mailCheck2);			 

        $password = new Zend_Form_Element_Password('password');
        $password->setLabel('Mot de passe')
        		 ->setRequired(true)
        		 ->addFilter('StripTags')
        		 ->addFilter('StringTrim')
        		 ->addValidator('NotEmpty')
        		 ->addDecorator($decorators);
        $this->addElement($password);

        //$same_password_validator = new ValidSamePassword($this->getValue('password'));        

        $password_bis = new Zend_Form_Element_Password('password_confirmation');
        $password_bis->setLabel('Retapez le mot de passe')
		        ->setRequired(true)
		        ->addFilter('StripTags')
		        ->addFilter('StringTrim')
		        ->addValidator('NotEmpty')
		        ->addDecorator($decorators);
        $this->addElement($password_bis);
        
        
		// add person zipcode
		$site = new Zend_Form_Element_Text('url');
		$site->addFilter('StripTags')
		         //->setValue($data['zipcode'])
		         ->addFilter('StringTrim')
		         ->setAttrib('class', 'textfield')
		         ->setLabel(('Adresse du site de l\'Apel de votre etablissement'))
				 ->addDecorator($decorators);
		$this->addElement($site);			

		 // add person address
		$address = new Zend_Form_Element_Textarea('address');
		$address //->setValue($data['address'])
	         	 ->addFilter('StripTags')
		         ->addFilter('StringTrim')
		         ->setAttrib('class', 'textfield')
		         ->setLabel(('PERSON ADDRESS'))
		         ->setAttrib('rows',3) 
		         ->setAttrib('cols',23)
			 	 ->addDecorator($decorators);
	 	$this->addElement($address);
	 		
		// add person zipcode
		$zipcode = new Zend_Form_Element_Text('zipcode');
		$zipcode->addFilter('StripTags')
		         //->setValue($data['zipcode'])
		         ->addFilter('StringTrim')
		         ->setAttrib('class', 'textfield')
		         ->setAttrib('maxlength', '5')
		         ->setLabel(('PERSON ZIPCODE'))
				 ->addDecorator($decorators);
		$this->addElement($zipcode);
					
		// add person city
		$city = new Zend_Form_Element_Text('city');
		$city //->setValue($data['city'])
		         ->addFilter('StripTags')
		         ->addFilter('StringTrim')
		         ->setAttrib('class', 'textfield')
		         ->setLabel(('PERSON CITY'))
				 ->addDecorator($decorators);
		$this->addElement($city);
							
		// add person phone
		$phone = new Zend_Form_Element_Text('telephone');
		$phone //->setValue($data['telephone'])
		         ->addFilter('StripTags')
		         ->addFilter('StringTrim')
		         ->setAttrib('class', 'textfield')
		         ->setAttrib('maxlength', '14')
		         ->setLabel(('PERSON PHONE'))
				 ->addDecorator($decorators);
				 $this->addElement($phone);	
				 				
		// add person fax
		$fax = new Zend_Form_Element_Text('fax');
		$fax //->setValue($data['fax'])
	         ->addFilter('StripTags')
	         ->addFilter('StringTrim')
	         ->setAttrib('class', 'textfield')
	         ->setAttrib('maxlength', '14')
	         ->setLabel(('PERSON FAX'))
			 ->addDecorator($decorators);	 
        $this->addElement($fax);
        		

		 $adresseCheck = new Zend_Form_Element_Checkbox('basic_informations_person_show');
		 $adresseCheck->addFilter('StripTags')
	        	 	 ->addFilter('StringTrim')
	        		 ->setLabel(("J'accepte que ces informations figurent dans l'annuaire de l'intranet"))
	        		 ->addDecorator($decorators);
	     $this->addElement($adresseCheck);			 
		
		$mobile = new Zend_Form_Element_Text('mobilephone');
		$mobile //->setValue($data['telephone'])
			         ->addFilter('StripTags')
			         ->addFilter('StringTrim')
			         ->setAttrib('class', 'textfield')
			         ->setAttrib('maxlength', '14')
			         ->setLabel(('PERSON MOBILE'))
					 ->addDecorator($decorators);
		$this->addElement($mobile);	

		$mobileCheck = new Zend_Form_Element_Checkbox('mobilephone_show');
		$mobileCheck->addFilter('StripTags')
	        	 	 ->addFilter('StringTrim')
	        		 ->setLabel(("J'accepte que mon téléphone portable figure dans l'annuaire de l'intranet"))
	        		 ->addDecorator($decorators);
	    $this->addElement($mobileCheck);

	        		 
	        		 
		$fonction = new Zend_Form_Element_Radio('function_choice',array('label_style' => 'float: left;')); 
		$fonction->setLabel('Fonction');
		$fonction -> setMultiOptions(array(
									'permanent'=>'Permanent', 
									'elu'=>'Elu',
									'animateurbdi'=>'Animateur BDI',
									'personneressource'=>'Personne Ressource')) 
		
		         -> setOptions(array('separator' => '')) 
		         -> addDecorator($decorators)
				 ->setOptions(array('label_style' => 'float: left; width: 70%; margin-left: 185px;'));    		 
		$this->addElement($fonction);      		 	        		 

	        		 
        $function_list_perm = new Zend_Form_Element_Select('function_list_perm');
		$function_list_perm-> addDecorator($decorators);
		$function_list_perm->setLabel(null);
        $this->addElement($function_list_perm);   
			 
        $function_list_elu = new Zend_Form_Element_Select('function_list_elu');
		$function_list_elu-> addDecorator($decorators);
        $this->addElement($function_list_elu);   
         
	        		 
        $function_list_anim = new Zend_Form_Element_Select('function_list_anim');
		$function_list_anim-> addDecorator($decorators);
      	$this->addElement($function_list_anim);   
         
        $function_list_pers = new Zend_Form_Element_Select('function_list_pers');
		$function_list_pers-> addDecorator($decorators);
      	$this->addElement($function_list_pers);   
      	
	        		 
	        		 
	        		 
	        		 
		$echelon = new Zend_Form_Element_Radio('choix_echelon',array('label_style' => 'float: left;')); 
		$echelon->setLabel('Echelon dont vous dependez');
		$echelon -> setMultiOptions(array(
									'etablissement'=>'Apel d\'etablissement', 
									'departementale'=>'Apel departementale',
									'academique'=>'Apel academique',
									'nationale'=>'Apel nationale')) 
		
		         -> setOptions(array('separator' => ''))
		         -> addDecorator($decorators)
				 ->setOptions(array('label_style' => 'float: left; width: 70%; margin-left: 185px; padding-bottom: 25px;'));    		 
	    $this->addElement($echelon);      		 
        		 
		$choix_echelon_depa = new Zend_Form_Element_Select('choix_echelon_depa');
		$choix_echelon_depa-> addDecorator($decorators); 
        //$choix_echelon_etab->addMultiOptions(array("mademoiselle" => "Mademoiselle", "madame" => "Madame", "pere" => "Père", "frere" => "Frère", "Soeur" => "Soeur" ));
        $this->addElement($choix_echelon_depa);   
			 
        $choix_echelon_city = new Zend_Form_Element_Select('choix_echelon_city');
		$choix_echelon_city-> addDecorator($decorators);
        $choix_echelon_city->addMultiOptions(array("mademoiselle" => "Mademoiselle", "madame" => "Madame", "pere" => "Père", "frere" => "Frère", "Soeur" => "Soeur" ));
        $this->addElement($choix_echelon_city);   
         
	        		 
        $choix_echelon_etab = new Zend_Form_Element_Select('choix_echelon_etab');
		$choix_echelon_etab->addDecorator($decorators); 
        //$choix_echelon_etab->addMultiOptions(array("mademoiselle" => "Mademoiselle", "madame" => "Madame", "pere" => "Père", "frere" => "Frère", "Soeur" => "Soeur" ));
        $this->addElement($choix_echelon_etab);   
         
        
        
        $departement_list = new Zend_Form_Element_Select('departement_list');
		$departement_list-> addDecorator($decorators) ;
        
        $this->addElement($departement_list);   
         
	        		 
        $academique_list = new Zend_Form_Element_Select('academique_list');
		$academique_list-> addDecorator($decorators) ;
        //$nat->addMultiOptions(array("mademoiselle" => "Mademoiselle", "madame" => "Madame", "pere" => "Père", "frere" => "Frère", "Soeur" => "Soeur" ));
        $this->addElement($academique_list);   
  	        		 
		$aucun = new Zend_Form_Element_Checkbox('aucun');
		$aucun->addFilter('StripTags')
	        	 	 ->addFilter('StringTrim')
	        		 ->setLabel(("Aucun"))
	        		 ->addDecorator($decorators);
	    $this->addElement($aucun);
                
		$icf = new Zend_Form_Element_Checkbox('icf');
		$icf->addFilter('StripTags')
	        	 	 ->addFilter('StringTrim')
	        		 ->setLabel(("UCF"))
	        		 ->addDecorator($decorators);
	    $this->addElement($icf);
	    
		$ecole = new Zend_Form_Element_Checkbox('ecole');
		$ecole->addFilter('StripTags')
	        	 	 ->addFilter('StringTrim')
	        		 ->setLabel(("Ecole et monde professionnel"))
	        		 ->addDecorator($decorators);
	    $this->addElement($ecole);
	    
		$pastorale = new Zend_Form_Element_Checkbox('pastorale');
		$pastorale->addFilter('StripTags')
	        	 	 ->addFilter('StringTrim')
	        		 ->setLabel(("Pastorale"))
	        		 ->addDecorator($decorators);
	    $this->addElement($pastorale);
	    
		$securite = new Zend_Form_Element_Checkbox('securite');
		$securite->addFilter('StripTags')
	        	 	 ->addFilter('StringTrim')
	        		 ->setLabel(("Securite aux abords des etablissements"))
	        		 ->addDecorator($decorators);
	    $this->addElement($securite);
        
	    $this->addElement('hidden', 'new_parent_id', array('value' =>'0',
            'decorators' => array('ViewHelper',
                array(array('div' => 'HtmlTag'), array('tag' => 'div', 'class' => "hidden")))
        ));
	    
        $this->addElement(
                'submit',
                'resume_submit',
                array(
                    'decorators' => array(
                        'ViewHelper',
                        'Errors',
                        array('Description', array('tag' => 'p', 'class' => 'description')),
                        array('HtmlTag', array('tag' => 'span', 'class' => "aligne-centre ")),
                        array(array('div' => 'HtmlTag'),
                            array('tag' => 'p', 'class' => "form-table"))
                    ),
                    'label' => 'Valider',
                    'class'=>'btn_submit'
        ))->clearDecorators();
	    
	}
    public function save($data){
       
        $id = $this->table_Persons->savePerson($data);
        return $id;
    }
    
    //Remplis les données du form
    public function getDataForm($id,$format_date = true)
    {
           $data =array();
           $tab_Person =  $this->table_Persons->fetchAll("id = '$id'");
           $data = $tab_Person->toArray();
           $data = $data[0];
           
           return $data;
    }	
}
